//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/*
 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Thomas Roell not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Thomas Roell makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Thomas Roell, roell@informatik.tu-muenchen.de
 *
 */

#ifndef _XF86_GDIVGA_H_
#define _XF86_GDIVGA_H_

#define VGA2_PATCHLEVEL "0"
#define VGA16_PATCHLEVEL "0"
#define SVGA_PATCHLEVEL "0"

#include "X.h"
#include "misc.h"
#include "scrnintstr.h"

extern int vgaIOBase;
extern int vgaInterlaceType;
extern pointer vgaNewVideoState;
extern pointer vgaBase;              /* the framebuffer himself */

typedef struct {
  unsigned char MiscOutReg;     /* */
  unsigned char CRTC[25];       /* Crtc Controller */
  unsigned char Sequencer[5];   /* Video Sequencer */
  unsigned char Graphics[9];    /* Video Graphics */
  unsigned char Attribute[21];  /* Video Atribute */
  unsigned char DAC[768];       /* Internal Colorlookuptable */
  char NoClock;                 /* number of selected clock */
  pointer FontInfo1;            /* save area for fonts in plane 2 */
  pointer FontInfo2;            /* save area for fonts in plane 3 */
  pointer TextInfo;             /* save area for text */
} vgaHWRec, *vgaHWPtr;

#define OVERSCAN 0x11        /* Index of OverScan register */

#ifdef MONOVGA
#define BIT_PLANE 3        /* Which plane we write to in mono mode */
#else
#define BITS_PER_GUN 6
#define COLORMAP_SIZE 256

#endif

#define DACDelay \
    { \
        unsigned char temp = Inb(vgaIOBase + 0x0A); \
        temp = Inb(vgaIOBase + 0x0A); \
    }

/*
#ifdef MONOVGA
#define SvgaInfoRec vga2InfoRec
#endif
#ifdef XF86VGA16
#define SvgaInfoRec vga16InfoRec
#define vga2InfoRec vga16InfoRec
#endif
#ifdef S3_SERVER
#define SvgaInfoRec SvgaInfoRec
#endif
#ifdef MACH32_SERVER
#define SvgaInfoRec mach32InfoRec
#endif
#ifdef MACH64_SERVER
#define SvgaInfoRec mach64InfoRec
#endif
#ifdef AGX_SERVER
#define SvgaInfoRec agxInfoRec
#endif
*/
extern ScrnInfoRec SvgaInfoRec;

/* Values for vgaInterlaceType */
#define VGA_NO_DIVIDE_VERT     0
#define VGA_DIVIDE_VERT        1

/*
 * This are used to tell the ChipSaveScreen() functions to save/restore
 * anything that must be retained across a synchronous reset of the SVGA
 */
#define SS_START        0
#define SS_FINISH        1

/*
 * List of I/O ports for generic VGA
 */
extern unsigned VGA_IOPorts[];
extern int Num_VGA_IOPorts;

/* Function Prototypes */

/* vgaHW.c */
void vgaProtect(
    _ELASTOS Boolean on
);

_ELASTOS Boolean vgaSaveScreen(
    ScreenPtr pScreen,
    _ELASTOS Boolean on
);

void vgaHWSaveScreen(
    long start
);

void vgaHWRestore(
    vgaHWPtr restore
);

void *vgaHWSave(
    vgaHWPtr save,
    int size
);

_ELASTOS Boolean vgaHWInit(
    DisplayModePtr mode,
    int size
);

void vgaGetClocks(
    int num,
    _ELASTOS Boolean (*ClockFunc)(int)
);

void vgaDPMSSet(
    int PowerManagementMode
);

//#define __DEBUGAL__

#ifndef __DEBUGAL__
#undef kprintf
#define kprintf(x, ...)
#endif

#endif /* _XF86_GDIVGA_H_ */
